{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "flower_type_pred_v6.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "082062007d9144ba93964d252aeeb70b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_8544d3d7643141789ddebb76b03fc221",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_c771957fe81245bd8c50f5c394fa186b",
              "IPY_MODEL_2470fc20cceb46229f2bf315ce45c30f"
            ]
          }
        },
        "8544d3d7643141789ddebb76b03fc221": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "c771957fe81245bd8c50f5c394fa186b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_acc8fad7e78f451eb46b78bafcc48dfe",
            "_dom_classes": [],
            "description": "100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 4,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 4,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_4e3d2c1412f447199cd985a22e37e92f"
          }
        },
        "2470fc20cceb46229f2bf315ce45c30f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_fd8f7e3086e245d388bb7f26b8479d34",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 4/4 [00:26&lt;00:00,  6.72s/it]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_51a15365332a45a294d0de92e64a3146"
          }
        },
        "acc8fad7e78f451eb46b78bafcc48dfe": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "4e3d2c1412f447199cd985a22e37e92f": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "fd8f7e3086e245d388bb7f26b8479d34": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "51a15365332a45a294d0de92e64a3146": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "0f57443fb7d541e399e600948fe05891": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_c69e89b00dd24207b3b59699b04a1198",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_1cd4638f061949c6ab0a19e5452bb45e",
              "IPY_MODEL_5316eed72bf94cc6a2ca502fb6e6d539"
            ]
          }
        },
        "c69e89b00dd24207b3b59699b04a1198": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "1cd4638f061949c6ab0a19e5452bb45e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_f65fe566bf4c4440a0a0fa1212ea0d1e",
            "_dom_classes": [],
            "description": "100%",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 6,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 6,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_876d985d45a541b483074e45e0812c2a"
          }
        },
        "5316eed72bf94cc6a2ca502fb6e6d539": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_19eca8e120074b96b26862d519d1414f",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 6/6 [00:00&lt;00:00,  7.82it/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_5882d8d51a2e4717856902ee184639f4"
          }
        },
        "f65fe566bf4c4440a0a0fa1212ea0d1e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "initial",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "876d985d45a541b483074e45e0812c2a": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "19eca8e120074b96b26862d519d1414f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "5882d8d51a2e4717856902ee184639f4": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "invb01u8bdOv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "ver = 'v6'"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VfcmbjtpVLW2",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "from sklearn.model_selection import *\n",
        "from sklearn.preprocessing import *\n",
        "from sklearn.metrics import *\n",
        "from lightgbm import LGBMClassifier\n",
        "\n",
        "import gc\n",
        "from tqdm import *"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Zln8E9QHVcyl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "train = pd.read_csv('Train.csv')\n",
        "test = pd.read_csv('Test.csv')\n",
        "ss = pd.read_csv('sample_submission.csv')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_0qBLg1oV4ML",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df = pd.concat([train, test]).reset_index(drop = True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wtenMrqX2nf5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 160
        },
        "outputId": "e362f20a-dd2a-48c1-9cfb-27bcb83cea0d"
      },
      "source": [
        "df.nunique()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Area_Code        30900\n",
              "Locality_Code       22\n",
              "Region_Code       2185\n",
              "Height             110\n",
              "Diameter           151\n",
              "Class                8\n",
              "Species            263\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mtQT91gocqaE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df['height*diameter'] = df['Height'] * df['Diameter']\n",
        "df['height/diameter'] = df['Height'] / df['Diameter']"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cA28gxU3c3XB",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        },
        "outputId": "96c1ab5a-6325-4b6b-936c-aa3e37c12464"
      },
      "source": [
        "df.columns"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['Area_Code', 'Locality_Code', 'Region_Code', 'Height', 'Diameter',\n",
              "       'Class', 'Species', 'height*diameter', 'height/diameter'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "B_HkJYbic6-Z",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 120,
          "referenced_widgets": [
            "082062007d9144ba93964d252aeeb70b",
            "8544d3d7643141789ddebb76b03fc221",
            "c771957fe81245bd8c50f5c394fa186b",
            "2470fc20cceb46229f2bf315ce45c30f",
            "acc8fad7e78f451eb46b78bafcc48dfe",
            "4e3d2c1412f447199cd985a22e37e92f",
            "fd8f7e3086e245d388bb7f26b8479d34",
            "51a15365332a45a294d0de92e64a3146"
          ]
        },
        "outputId": "d3a54aff-873d-40c3-887c-96d48275c3d6"
      },
      "source": [
        "cat_fts = ['Area_Code', 'Locality_Code', 'Region_Code', 'Species']\n",
        "num_fts = ['Height', 'Diameter','height*diameter', 'height/diameter']\n",
        "\n",
        "for g in tqdm_notebook(cat_fts):\n",
        "\n",
        "  grp = df.groupby(g)[num_fts].mean()\n",
        "  grp.columns = [c + f'_grpd_by_{g}_mean' for c in grp.columns]\n",
        "  df = pd.merge(df, grp, on = g, how = 'left')\n",
        "\n",
        "  grp = df.groupby(g)[num_fts].std()\n",
        "  grp.columns = [c + f'_grpd_by_{g}_std' for c in grp.columns]\n",
        "  df = pd.merge(df, grp, on = g, how = 'left')\n",
        "\n",
        "  grp = df.groupby(g)[num_fts].min()\n",
        "  grp.columns = [c + f'_grpd_by_{g}_min' for c in grp.columns]\n",
        "  df = pd.merge(df, grp, on = g, how = 'left')\n",
        "\n",
        "  grp = df.groupby(g)[num_fts].max()\n",
        "  grp.columns = [c + f'_grpd_by_{g}_max' for c in grp.columns]\n",
        "  df = pd.merge(df, grp, on = g, how = 'left')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0\n",
            "Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`\n",
            "  after removing the cwd from sys.path.\n"
          ],
          "name": "stderr"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "082062007d9144ba93964d252aeeb70b",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, max=4.0), HTML(value='')))"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QfJ8wl58W2Hz",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 120,
          "referenced_widgets": [
            "0f57443fb7d541e399e600948fe05891",
            "c69e89b00dd24207b3b59699b04a1198",
            "1cd4638f061949c6ab0a19e5452bb45e",
            "5316eed72bf94cc6a2ca502fb6e6d539",
            "f65fe566bf4c4440a0a0fa1212ea0d1e",
            "876d985d45a541b483074e45e0812c2a",
            "19eca8e120074b96b26862d519d1414f",
            "5882d8d51a2e4717856902ee184639f4"
          ]
        },
        "outputId": "9ba1486c-33ab-437f-8c49-36154fbc6fc2"
      },
      "source": [
        "fts = ['Area_Code','Locality_Code','Region_Code','Height','Diameter', 'Species']\n",
        "for g in tqdm_notebook(fts):\n",
        "  rf = [c for c in fts if c != g]\n",
        "  grp = df.groupby(g)[rf].nunique()\n",
        "  grp.columns = [c + f'_grpd_by_{g}_nunique' for c in grp.columns]\n",
        "  df = pd.merge(df, grp, on = g, how = 'left')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0\n",
            "Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`\n",
            "  \n"
          ],
          "name": "stderr"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "0f57443fb7d541e399e600948fe05891",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "HBox(children=(FloatProgress(value=0.0, max=6.0), HTML(value='')))"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jLmGNPFObn2N",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "for f in fts:\n",
        "  df[f + '_freq'] = df[f].map(df[f].value_counts(normalize = True))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jSdWOa2hX7Uc",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "train, test = df[:train.shape[0]].reset_index(drop = True), df[train.shape[0]:].reset_index(drop = True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ag23_zOcXvxP",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "features = [c for c in train.columns if c not in ['Class', \"Area_Code\"]]"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BchuAjlmWnFd",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "3fe71674-5e77-4b79-9a95-ca3ef09ec3fa"
      },
      "source": [
        "oofs = np.zeros((len(train), 8))\n",
        "preds = np.zeros((len(test), 8))\n",
        "N_SPLITS = 15\n",
        "folds = StratifiedKFold(N_SPLITS, shuffle = True, random_state = 77)\n",
        "\n",
        "for fold_, (trn_idx, val_idx) in enumerate(folds.split(train, train['Class'])):\n",
        "\n",
        "  print(f'\\n\\n Fold {fold_} \\\\n\\n')\n",
        "  X_trn, y_trn = train[features].iloc[trn_idx], train[\"Class\"][trn_idx]\n",
        "  X_val, y_val = train[features].iloc[val_idx], train[\"Class\"][val_idx]\n",
        "\n",
        "  clf = LGBMClassifier(n_estimators = 2000, learning_rate = 0.03, colsample_bytree = 0.3, reg_alpha = 0.5, reg_lambda = 2, random_state = 2)\n",
        "\n",
        "  clf.fit(X_trn, y_trn, eval_set = [(X_val, y_val)], early_stopping_rounds = 200, verbose = 50, eval_metric = 'logloss')\n",
        "\n",
        "  oofs[val_idx] = clf.predict_proba(X_val)\n",
        "  preds += clf.predict_proba(test[features]) / N_SPLITS\n"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\n",
            "\n",
            " Fold 0 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 1.00786\tvalid_0's multi_logloss: 1.00786\n",
            "[100]\tvalid_0's multi_logloss: 0.866884\tvalid_0's multi_logloss: 0.866884\n",
            "[150]\tvalid_0's multi_logloss: 0.81391\tvalid_0's multi_logloss: 0.81391\n",
            "[200]\tvalid_0's multi_logloss: 0.787964\tvalid_0's multi_logloss: 0.787964\n",
            "[250]\tvalid_0's multi_logloss: 0.774951\tvalid_0's multi_logloss: 0.774951\n",
            "[300]\tvalid_0's multi_logloss: 0.766229\tvalid_0's multi_logloss: 0.766229\n",
            "[350]\tvalid_0's multi_logloss: 0.760503\tvalid_0's multi_logloss: 0.760503\n",
            "[400]\tvalid_0's multi_logloss: 0.757054\tvalid_0's multi_logloss: 0.757054\n",
            "[450]\tvalid_0's multi_logloss: 0.754423\tvalid_0's multi_logloss: 0.754423\n",
            "[500]\tvalid_0's multi_logloss: 0.752673\tvalid_0's multi_logloss: 0.752673\n",
            "[550]\tvalid_0's multi_logloss: 0.751944\tvalid_0's multi_logloss: 0.751944\n",
            "[600]\tvalid_0's multi_logloss: 0.752293\tvalid_0's multi_logloss: 0.752293\n",
            "[650]\tvalid_0's multi_logloss: 0.752031\tvalid_0's multi_logloss: 0.752031\n",
            "[700]\tvalid_0's multi_logloss: 0.753045\tvalid_0's multi_logloss: 0.753045\n",
            "[750]\tvalid_0's multi_logloss: 0.753881\tvalid_0's multi_logloss: 0.753881\n",
            "[800]\tvalid_0's multi_logloss: 0.755499\tvalid_0's multi_logloss: 0.755499\n",
            "Early stopping, best iteration is:\n",
            "[633]\tvalid_0's multi_logloss: 0.751695\tvalid_0's multi_logloss: 0.751695\n",
            "\n",
            "\n",
            " Fold 1 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.986542\tvalid_0's multi_logloss: 0.986542\n",
            "[100]\tvalid_0's multi_logloss: 0.84225\tvalid_0's multi_logloss: 0.84225\n",
            "[150]\tvalid_0's multi_logloss: 0.790313\tvalid_0's multi_logloss: 0.790313\n",
            "[200]\tvalid_0's multi_logloss: 0.764865\tvalid_0's multi_logloss: 0.764865\n",
            "[250]\tvalid_0's multi_logloss: 0.750217\tvalid_0's multi_logloss: 0.750217\n",
            "[300]\tvalid_0's multi_logloss: 0.744203\tvalid_0's multi_logloss: 0.744203\n",
            "[350]\tvalid_0's multi_logloss: 0.739445\tvalid_0's multi_logloss: 0.739445\n",
            "[400]\tvalid_0's multi_logloss: 0.736589\tvalid_0's multi_logloss: 0.736589\n",
            "[450]\tvalid_0's multi_logloss: 0.734563\tvalid_0's multi_logloss: 0.734563\n",
            "[500]\tvalid_0's multi_logloss: 0.73365\tvalid_0's multi_logloss: 0.73365\n",
            "[550]\tvalid_0's multi_logloss: 0.732879\tvalid_0's multi_logloss: 0.732879\n",
            "[600]\tvalid_0's multi_logloss: 0.732888\tvalid_0's multi_logloss: 0.732888\n",
            "[650]\tvalid_0's multi_logloss: 0.734355\tvalid_0's multi_logloss: 0.734355\n",
            "[700]\tvalid_0's multi_logloss: 0.735377\tvalid_0's multi_logloss: 0.735377\n",
            "Early stopping, best iteration is:\n",
            "[545]\tvalid_0's multi_logloss: 0.732317\tvalid_0's multi_logloss: 0.732317\n",
            "\n",
            "\n",
            " Fold 2 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.96764\tvalid_0's multi_logloss: 0.96764\n",
            "[100]\tvalid_0's multi_logloss: 0.812262\tvalid_0's multi_logloss: 0.812262\n",
            "[150]\tvalid_0's multi_logloss: 0.752151\tvalid_0's multi_logloss: 0.752151\n",
            "[200]\tvalid_0's multi_logloss: 0.722232\tvalid_0's multi_logloss: 0.722232\n",
            "[250]\tvalid_0's multi_logloss: 0.705536\tvalid_0's multi_logloss: 0.705536\n",
            "[300]\tvalid_0's multi_logloss: 0.695816\tvalid_0's multi_logloss: 0.695816\n",
            "[350]\tvalid_0's multi_logloss: 0.690121\tvalid_0's multi_logloss: 0.690121\n",
            "[400]\tvalid_0's multi_logloss: 0.68427\tvalid_0's multi_logloss: 0.68427\n",
            "[450]\tvalid_0's multi_logloss: 0.680294\tvalid_0's multi_logloss: 0.680294\n",
            "[500]\tvalid_0's multi_logloss: 0.677311\tvalid_0's multi_logloss: 0.677311\n",
            "[550]\tvalid_0's multi_logloss: 0.674566\tvalid_0's multi_logloss: 0.674566\n",
            "[600]\tvalid_0's multi_logloss: 0.672782\tvalid_0's multi_logloss: 0.672782\n",
            "[650]\tvalid_0's multi_logloss: 0.670918\tvalid_0's multi_logloss: 0.670918\n",
            "[700]\tvalid_0's multi_logloss: 0.671871\tvalid_0's multi_logloss: 0.671871\n",
            "[750]\tvalid_0's multi_logloss: 0.67254\tvalid_0's multi_logloss: 0.67254\n",
            "[800]\tvalid_0's multi_logloss: 0.672833\tvalid_0's multi_logloss: 0.672833\n",
            "Early stopping, best iteration is:\n",
            "[648]\tvalid_0's multi_logloss: 0.670918\tvalid_0's multi_logloss: 0.670918\n",
            "\n",
            "\n",
            " Fold 3 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.992501\tvalid_0's multi_logloss: 0.992501\n",
            "[100]\tvalid_0's multi_logloss: 0.83874\tvalid_0's multi_logloss: 0.83874\n",
            "[150]\tvalid_0's multi_logloss: 0.780944\tvalid_0's multi_logloss: 0.780944\n",
            "[200]\tvalid_0's multi_logloss: 0.753232\tvalid_0's multi_logloss: 0.753232\n",
            "[250]\tvalid_0's multi_logloss: 0.737361\tvalid_0's multi_logloss: 0.737361\n",
            "[300]\tvalid_0's multi_logloss: 0.728928\tvalid_0's multi_logloss: 0.728928\n",
            "[350]\tvalid_0's multi_logloss: 0.723008\tvalid_0's multi_logloss: 0.723008\n",
            "[400]\tvalid_0's multi_logloss: 0.719847\tvalid_0's multi_logloss: 0.719847\n",
            "[450]\tvalid_0's multi_logloss: 0.716783\tvalid_0's multi_logloss: 0.716783\n",
            "[500]\tvalid_0's multi_logloss: 0.715148\tvalid_0's multi_logloss: 0.715148\n",
            "[550]\tvalid_0's multi_logloss: 0.71358\tvalid_0's multi_logloss: 0.71358\n",
            "[600]\tvalid_0's multi_logloss: 0.713938\tvalid_0's multi_logloss: 0.713938\n",
            "[650]\tvalid_0's multi_logloss: 0.71417\tvalid_0's multi_logloss: 0.71417\n",
            "[700]\tvalid_0's multi_logloss: 0.7148\tvalid_0's multi_logloss: 0.7148\n",
            "[750]\tvalid_0's multi_logloss: 0.715253\tvalid_0's multi_logloss: 0.715253\n",
            "Early stopping, best iteration is:\n",
            "[572]\tvalid_0's multi_logloss: 0.713169\tvalid_0's multi_logloss: 0.713169\n",
            "\n",
            "\n",
            " Fold 4 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.962593\tvalid_0's multi_logloss: 0.962593\n",
            "[100]\tvalid_0's multi_logloss: 0.80013\tvalid_0's multi_logloss: 0.80013\n",
            "[150]\tvalid_0's multi_logloss: 0.739705\tvalid_0's multi_logloss: 0.739705\n",
            "[200]\tvalid_0's multi_logloss: 0.712189\tvalid_0's multi_logloss: 0.712189\n",
            "[250]\tvalid_0's multi_logloss: 0.695382\tvalid_0's multi_logloss: 0.695382\n",
            "[300]\tvalid_0's multi_logloss: 0.687016\tvalid_0's multi_logloss: 0.687016\n",
            "[350]\tvalid_0's multi_logloss: 0.680873\tvalid_0's multi_logloss: 0.680873\n",
            "[400]\tvalid_0's multi_logloss: 0.67548\tvalid_0's multi_logloss: 0.67548\n",
            "[450]\tvalid_0's multi_logloss: 0.672074\tvalid_0's multi_logloss: 0.672074\n",
            "[500]\tvalid_0's multi_logloss: 0.669699\tvalid_0's multi_logloss: 0.669699\n",
            "[550]\tvalid_0's multi_logloss: 0.668805\tvalid_0's multi_logloss: 0.668805\n",
            "[600]\tvalid_0's multi_logloss: 0.669262\tvalid_0's multi_logloss: 0.669262\n",
            "[650]\tvalid_0's multi_logloss: 0.670119\tvalid_0's multi_logloss: 0.670119\n",
            "[700]\tvalid_0's multi_logloss: 0.670859\tvalid_0's multi_logloss: 0.670859\n",
            "[750]\tvalid_0's multi_logloss: 0.672912\tvalid_0's multi_logloss: 0.672912\n",
            "Early stopping, best iteration is:\n",
            "[567]\tvalid_0's multi_logloss: 0.668656\tvalid_0's multi_logloss: 0.668656\n",
            "\n",
            "\n",
            " Fold 5 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.985739\tvalid_0's multi_logloss: 0.985739\n",
            "[100]\tvalid_0's multi_logloss: 0.838723\tvalid_0's multi_logloss: 0.838723\n",
            "[150]\tvalid_0's multi_logloss: 0.784507\tvalid_0's multi_logloss: 0.784507\n",
            "[200]\tvalid_0's multi_logloss: 0.757397\tvalid_0's multi_logloss: 0.757397\n",
            "[250]\tvalid_0's multi_logloss: 0.740754\tvalid_0's multi_logloss: 0.740754\n",
            "[300]\tvalid_0's multi_logloss: 0.731639\tvalid_0's multi_logloss: 0.731639\n",
            "[350]\tvalid_0's multi_logloss: 0.725659\tvalid_0's multi_logloss: 0.725659\n",
            "[400]\tvalid_0's multi_logloss: 0.722516\tvalid_0's multi_logloss: 0.722516\n",
            "[450]\tvalid_0's multi_logloss: 0.719557\tvalid_0's multi_logloss: 0.719557\n",
            "[500]\tvalid_0's multi_logloss: 0.718295\tvalid_0's multi_logloss: 0.718295\n",
            "[550]\tvalid_0's multi_logloss: 0.71732\tvalid_0's multi_logloss: 0.71732\n",
            "[600]\tvalid_0's multi_logloss: 0.716898\tvalid_0's multi_logloss: 0.716898\n",
            "[650]\tvalid_0's multi_logloss: 0.717725\tvalid_0's multi_logloss: 0.717725\n",
            "[700]\tvalid_0's multi_logloss: 0.719351\tvalid_0's multi_logloss: 0.719351\n",
            "[750]\tvalid_0's multi_logloss: 0.720616\tvalid_0's multi_logloss: 0.720616\n",
            "Early stopping, best iteration is:\n",
            "[595]\tvalid_0's multi_logloss: 0.716506\tvalid_0's multi_logloss: 0.716506\n",
            "\n",
            "\n",
            " Fold 6 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.978353\tvalid_0's multi_logloss: 0.978353\n",
            "[100]\tvalid_0's multi_logloss: 0.824257\tvalid_0's multi_logloss: 0.824257\n",
            "[150]\tvalid_0's multi_logloss: 0.765757\tvalid_0's multi_logloss: 0.765757\n",
            "[200]\tvalid_0's multi_logloss: 0.735874\tvalid_0's multi_logloss: 0.735874\n",
            "[250]\tvalid_0's multi_logloss: 0.719318\tvalid_0's multi_logloss: 0.719318\n",
            "[300]\tvalid_0's multi_logloss: 0.708581\tvalid_0's multi_logloss: 0.708581\n",
            "[350]\tvalid_0's multi_logloss: 0.702265\tvalid_0's multi_logloss: 0.702265\n",
            "[400]\tvalid_0's multi_logloss: 0.697656\tvalid_0's multi_logloss: 0.697656\n",
            "[450]\tvalid_0's multi_logloss: 0.694872\tvalid_0's multi_logloss: 0.694872\n",
            "[500]\tvalid_0's multi_logloss: 0.692672\tvalid_0's multi_logloss: 0.692672\n",
            "[550]\tvalid_0's multi_logloss: 0.69341\tvalid_0's multi_logloss: 0.69341\n",
            "[600]\tvalid_0's multi_logloss: 0.691972\tvalid_0's multi_logloss: 0.691972\n",
            "[650]\tvalid_0's multi_logloss: 0.692655\tvalid_0's multi_logloss: 0.692655\n",
            "[700]\tvalid_0's multi_logloss: 0.692792\tvalid_0's multi_logloss: 0.692792\n",
            "[750]\tvalid_0's multi_logloss: 0.69395\tvalid_0's multi_logloss: 0.69395\n",
            "[800]\tvalid_0's multi_logloss: 0.694989\tvalid_0's multi_logloss: 0.694989\n",
            "Early stopping, best iteration is:\n",
            "[612]\tvalid_0's multi_logloss: 0.691846\tvalid_0's multi_logloss: 0.691846\n",
            "\n",
            "\n",
            " Fold 7 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 1.00759\tvalid_0's multi_logloss: 1.00759\n",
            "[100]\tvalid_0's multi_logloss: 0.875325\tvalid_0's multi_logloss: 0.875325\n",
            "[150]\tvalid_0's multi_logloss: 0.829537\tvalid_0's multi_logloss: 0.829537\n",
            "[200]\tvalid_0's multi_logloss: 0.807823\tvalid_0's multi_logloss: 0.807823\n",
            "[250]\tvalid_0's multi_logloss: 0.796147\tvalid_0's multi_logloss: 0.796147\n",
            "[300]\tvalid_0's multi_logloss: 0.790879\tvalid_0's multi_logloss: 0.790879\n",
            "[350]\tvalid_0's multi_logloss: 0.78814\tvalid_0's multi_logloss: 0.78814\n",
            "[400]\tvalid_0's multi_logloss: 0.788176\tvalid_0's multi_logloss: 0.788176\n",
            "[450]\tvalid_0's multi_logloss: 0.787124\tvalid_0's multi_logloss: 0.787124\n",
            "[500]\tvalid_0's multi_logloss: 0.787181\tvalid_0's multi_logloss: 0.787181\n",
            "[550]\tvalid_0's multi_logloss: 0.787379\tvalid_0's multi_logloss: 0.787379\n",
            "[600]\tvalid_0's multi_logloss: 0.788343\tvalid_0's multi_logloss: 0.788343\n",
            "[650]\tvalid_0's multi_logloss: 0.790412\tvalid_0's multi_logloss: 0.790412\n",
            "Early stopping, best iteration is:\n",
            "[471]\tvalid_0's multi_logloss: 0.786459\tvalid_0's multi_logloss: 0.786459\n",
            "\n",
            "\n",
            " Fold 8 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.980784\tvalid_0's multi_logloss: 0.980784\n",
            "[100]\tvalid_0's multi_logloss: 0.830332\tvalid_0's multi_logloss: 0.830332\n",
            "[150]\tvalid_0's multi_logloss: 0.775992\tvalid_0's multi_logloss: 0.775992\n",
            "[200]\tvalid_0's multi_logloss: 0.749473\tvalid_0's multi_logloss: 0.749473\n",
            "[250]\tvalid_0's multi_logloss: 0.736257\tvalid_0's multi_logloss: 0.736257\n",
            "[300]\tvalid_0's multi_logloss: 0.729452\tvalid_0's multi_logloss: 0.729452\n",
            "[350]\tvalid_0's multi_logloss: 0.7266\tvalid_0's multi_logloss: 0.7266\n",
            "[400]\tvalid_0's multi_logloss: 0.724556\tvalid_0's multi_logloss: 0.724556\n",
            "[450]\tvalid_0's multi_logloss: 0.72274\tvalid_0's multi_logloss: 0.72274\n",
            "[500]\tvalid_0's multi_logloss: 0.721633\tvalid_0's multi_logloss: 0.721633\n",
            "[550]\tvalid_0's multi_logloss: 0.721525\tvalid_0's multi_logloss: 0.721525\n",
            "[600]\tvalid_0's multi_logloss: 0.721915\tvalid_0's multi_logloss: 0.721915\n",
            "[650]\tvalid_0's multi_logloss: 0.722278\tvalid_0's multi_logloss: 0.722278\n",
            "[700]\tvalid_0's multi_logloss: 0.723314\tvalid_0's multi_logloss: 0.723314\n",
            "Early stopping, best iteration is:\n",
            "[540]\tvalid_0's multi_logloss: 0.721269\tvalid_0's multi_logloss: 0.721269\n",
            "\n",
            "\n",
            " Fold 9 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.999555\tvalid_0's multi_logloss: 0.999555\n",
            "[100]\tvalid_0's multi_logloss: 0.860339\tvalid_0's multi_logloss: 0.860339\n",
            "[150]\tvalid_0's multi_logloss: 0.809636\tvalid_0's multi_logloss: 0.809636\n",
            "[200]\tvalid_0's multi_logloss: 0.786118\tvalid_0's multi_logloss: 0.786118\n",
            "[250]\tvalid_0's multi_logloss: 0.773069\tvalid_0's multi_logloss: 0.773069\n",
            "[300]\tvalid_0's multi_logloss: 0.765749\tvalid_0's multi_logloss: 0.765749\n",
            "[350]\tvalid_0's multi_logloss: 0.760509\tvalid_0's multi_logloss: 0.760509\n",
            "[400]\tvalid_0's multi_logloss: 0.757646\tvalid_0's multi_logloss: 0.757646\n",
            "[450]\tvalid_0's multi_logloss: 0.756066\tvalid_0's multi_logloss: 0.756066\n",
            "[500]\tvalid_0's multi_logloss: 0.754915\tvalid_0's multi_logloss: 0.754915\n",
            "[550]\tvalid_0's multi_logloss: 0.753105\tvalid_0's multi_logloss: 0.753105\n",
            "[600]\tvalid_0's multi_logloss: 0.75353\tvalid_0's multi_logloss: 0.75353\n",
            "[650]\tvalid_0's multi_logloss: 0.7538\tvalid_0's multi_logloss: 0.7538\n",
            "[700]\tvalid_0's multi_logloss: 0.754667\tvalid_0's multi_logloss: 0.754667\n",
            "Early stopping, best iteration is:\n",
            "[549]\tvalid_0's multi_logloss: 0.753103\tvalid_0's multi_logloss: 0.753103\n",
            "\n",
            "\n",
            " Fold 10 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.973964\tvalid_0's multi_logloss: 0.973964\n",
            "[100]\tvalid_0's multi_logloss: 0.825339\tvalid_0's multi_logloss: 0.825339\n",
            "[150]\tvalid_0's multi_logloss: 0.775183\tvalid_0's multi_logloss: 0.775183\n",
            "[200]\tvalid_0's multi_logloss: 0.752103\tvalid_0's multi_logloss: 0.752103\n",
            "[250]\tvalid_0's multi_logloss: 0.739619\tvalid_0's multi_logloss: 0.739619\n",
            "[300]\tvalid_0's multi_logloss: 0.733438\tvalid_0's multi_logloss: 0.733438\n",
            "[350]\tvalid_0's multi_logloss: 0.73047\tvalid_0's multi_logloss: 0.73047\n",
            "[400]\tvalid_0's multi_logloss: 0.728927\tvalid_0's multi_logloss: 0.728927\n",
            "[450]\tvalid_0's multi_logloss: 0.729441\tvalid_0's multi_logloss: 0.729441\n",
            "[500]\tvalid_0's multi_logloss: 0.729543\tvalid_0's multi_logloss: 0.729543\n",
            "[550]\tvalid_0's multi_logloss: 0.729816\tvalid_0's multi_logloss: 0.729816\n",
            "Early stopping, best iteration is:\n",
            "[389]\tvalid_0's multi_logloss: 0.728451\tvalid_0's multi_logloss: 0.728451\n",
            "\n",
            "\n",
            " Fold 11 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.982733\tvalid_0's multi_logloss: 0.982733\n",
            "[100]\tvalid_0's multi_logloss: 0.833102\tvalid_0's multi_logloss: 0.833102\n",
            "[150]\tvalid_0's multi_logloss: 0.778978\tvalid_0's multi_logloss: 0.778978\n",
            "[200]\tvalid_0's multi_logloss: 0.756805\tvalid_0's multi_logloss: 0.756805\n",
            "[250]\tvalid_0's multi_logloss: 0.744482\tvalid_0's multi_logloss: 0.744482\n",
            "[300]\tvalid_0's multi_logloss: 0.738515\tvalid_0's multi_logloss: 0.738515\n",
            "[350]\tvalid_0's multi_logloss: 0.734399\tvalid_0's multi_logloss: 0.734399\n",
            "[400]\tvalid_0's multi_logloss: 0.731521\tvalid_0's multi_logloss: 0.731521\n",
            "[450]\tvalid_0's multi_logloss: 0.730972\tvalid_0's multi_logloss: 0.730972\n",
            "[500]\tvalid_0's multi_logloss: 0.730953\tvalid_0's multi_logloss: 0.730953\n",
            "[550]\tvalid_0's multi_logloss: 0.731893\tvalid_0's multi_logloss: 0.731893\n",
            "[600]\tvalid_0's multi_logloss: 0.732646\tvalid_0's multi_logloss: 0.732646\n",
            "[650]\tvalid_0's multi_logloss: 0.734331\tvalid_0's multi_logloss: 0.734331\n",
            "Early stopping, best iteration is:\n",
            "[483]\tvalid_0's multi_logloss: 0.730408\tvalid_0's multi_logloss: 0.730408\n",
            "\n",
            "\n",
            " Fold 12 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.956946\tvalid_0's multi_logloss: 0.956946\n",
            "[100]\tvalid_0's multi_logloss: 0.804521\tvalid_0's multi_logloss: 0.804521\n",
            "[150]\tvalid_0's multi_logloss: 0.749881\tvalid_0's multi_logloss: 0.749881\n",
            "[200]\tvalid_0's multi_logloss: 0.724213\tvalid_0's multi_logloss: 0.724213\n",
            "[250]\tvalid_0's multi_logloss: 0.711164\tvalid_0's multi_logloss: 0.711164\n",
            "[300]\tvalid_0's multi_logloss: 0.702924\tvalid_0's multi_logloss: 0.702924\n",
            "[350]\tvalid_0's multi_logloss: 0.697968\tvalid_0's multi_logloss: 0.697968\n",
            "[400]\tvalid_0's multi_logloss: 0.694724\tvalid_0's multi_logloss: 0.694724\n",
            "[450]\tvalid_0's multi_logloss: 0.693235\tvalid_0's multi_logloss: 0.693235\n",
            "[500]\tvalid_0's multi_logloss: 0.692253\tvalid_0's multi_logloss: 0.692253\n",
            "[550]\tvalid_0's multi_logloss: 0.690841\tvalid_0's multi_logloss: 0.690841\n",
            "[600]\tvalid_0's multi_logloss: 0.691352\tvalid_0's multi_logloss: 0.691352\n",
            "[650]\tvalid_0's multi_logloss: 0.692979\tvalid_0's multi_logloss: 0.692979\n",
            "[700]\tvalid_0's multi_logloss: 0.694016\tvalid_0's multi_logloss: 0.694016\n",
            "[750]\tvalid_0's multi_logloss: 0.695496\tvalid_0's multi_logloss: 0.695496\n",
            "Early stopping, best iteration is:\n",
            "[561]\tvalid_0's multi_logloss: 0.690814\tvalid_0's multi_logloss: 0.690814\n",
            "\n",
            "\n",
            " Fold 13 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.999476\tvalid_0's multi_logloss: 0.999476\n",
            "[100]\tvalid_0's multi_logloss: 0.850073\tvalid_0's multi_logloss: 0.850073\n",
            "[150]\tvalid_0's multi_logloss: 0.795379\tvalid_0's multi_logloss: 0.795379\n",
            "[200]\tvalid_0's multi_logloss: 0.76849\tvalid_0's multi_logloss: 0.76849\n",
            "[250]\tvalid_0's multi_logloss: 0.753914\tvalid_0's multi_logloss: 0.753914\n",
            "[300]\tvalid_0's multi_logloss: 0.74703\tvalid_0's multi_logloss: 0.74703\n",
            "[350]\tvalid_0's multi_logloss: 0.74255\tvalid_0's multi_logloss: 0.74255\n",
            "[400]\tvalid_0's multi_logloss: 0.740119\tvalid_0's multi_logloss: 0.740119\n",
            "[450]\tvalid_0's multi_logloss: 0.739526\tvalid_0's multi_logloss: 0.739526\n",
            "[500]\tvalid_0's multi_logloss: 0.740068\tvalid_0's multi_logloss: 0.740068\n",
            "[550]\tvalid_0's multi_logloss: 0.74129\tvalid_0's multi_logloss: 0.74129\n",
            "[600]\tvalid_0's multi_logloss: 0.742781\tvalid_0's multi_logloss: 0.742781\n",
            "Early stopping, best iteration is:\n",
            "[428]\tvalid_0's multi_logloss: 0.739421\tvalid_0's multi_logloss: 0.739421\n",
            "\n",
            "\n",
            " Fold 14 \\n\n",
            "\n",
            "Training until validation scores don't improve for 200 rounds.\n",
            "[50]\tvalid_0's multi_logloss: 0.997477\tvalid_0's multi_logloss: 0.997477\n",
            "[100]\tvalid_0's multi_logloss: 0.848158\tvalid_0's multi_logloss: 0.848158\n",
            "[150]\tvalid_0's multi_logloss: 0.793673\tvalid_0's multi_logloss: 0.793673\n",
            "[200]\tvalid_0's multi_logloss: 0.765709\tvalid_0's multi_logloss: 0.765709\n",
            "[250]\tvalid_0's multi_logloss: 0.749495\tvalid_0's multi_logloss: 0.749495\n",
            "[300]\tvalid_0's multi_logloss: 0.74225\tvalid_0's multi_logloss: 0.74225\n",
            "[350]\tvalid_0's multi_logloss: 0.737497\tvalid_0's multi_logloss: 0.737497\n",
            "[400]\tvalid_0's multi_logloss: 0.734022\tvalid_0's multi_logloss: 0.734022\n",
            "[450]\tvalid_0's multi_logloss: 0.730766\tvalid_0's multi_logloss: 0.730766\n",
            "[500]\tvalid_0's multi_logloss: 0.72992\tvalid_0's multi_logloss: 0.72992\n",
            "[550]\tvalid_0's multi_logloss: 0.729606\tvalid_0's multi_logloss: 0.729606\n",
            "[600]\tvalid_0's multi_logloss: 0.730426\tvalid_0's multi_logloss: 0.730426\n",
            "[650]\tvalid_0's multi_logloss: 0.732129\tvalid_0's multi_logloss: 0.732129\n",
            "[700]\tvalid_0's multi_logloss: 0.73283\tvalid_0's multi_logloss: 0.73283\n",
            "Early stopping, best iteration is:\n",
            "[509]\tvalid_0's multi_logloss: 0.72936\tvalid_0's multi_logloss: 0.72936\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qT1rSXSha9BP",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "87c994ae-1259-473d-b9d4-5916507dc3a9"
      },
      "source": [
        "oof_val_score = log_loss(train['Class'], oofs)\n",
        "print(f'Final Log loss: {oof_val_score}')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Final Log loss: 0.7216102438734435\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mJN9Uq2CaDYa",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "ss[ss.columns.tolist()] = preds"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eMKXozZFaK4s",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 17
        },
        "outputId": "f27190fb-ba60-4e1c-a9cb-5ce6d7ef09ca"
      },
      "source": [
        "SUB_FILE_NAME = f'mft_{ver}.csv'\n",
        "ss.to_csv(SUB_FILE_NAME, index=False)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "application/javascript": [
              "\n",
              "    async function download(id, filename, size) {\n",
              "      if (!google.colab.kernel.accessAllowed) {\n",
              "        return;\n",
              "      }\n",
              "      const div = document.createElement('div');\n",
              "      const label = document.createElement('label');\n",
              "      label.textContent = `Downloading \"${filename}\": `;\n",
              "      div.appendChild(label);\n",
              "      const progress = document.createElement('progress');\n",
              "      progress.max = size;\n",
              "      div.appendChild(progress);\n",
              "      document.body.appendChild(div);\n",
              "\n",
              "      const buffers = [];\n",
              "      let downloaded = 0;\n",
              "\n",
              "      const channel = await google.colab.kernel.comms.open(id);\n",
              "      // Send a message to notify the kernel that we're ready.\n",
              "      channel.send({})\n",
              "\n",
              "      for await (const message of channel.messages) {\n",
              "        // Send a message to notify the kernel that we're ready.\n",
              "        channel.send({})\n",
              "        if (message.buffers) {\n",
              "          for (const buffer of message.buffers) {\n",
              "            buffers.push(buffer);\n",
              "            downloaded += buffer.byteLength;\n",
              "            progress.value = downloaded;\n",
              "          }\n",
              "        }\n",
              "      }\n",
              "      const blob = new Blob(buffers, {type: 'application/binary'});\n",
              "      const a = document.createElement('a');\n",
              "      a.href = window.URL.createObjectURL(blob);\n",
              "      a.download = filename;\n",
              "      div.appendChild(a);\n",
              "      a.click();\n",
              "      div.remove();\n",
              "    }\n",
              "  "
            ],
            "text/plain": [
              "<IPython.core.display.Javascript object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "application/javascript": [
              "download(\"download_03b9484c-9790-40f5-a806-61c6b11bcdf7\", \"mft_v6.csv\", 4982336)"
            ],
            "text/plain": [
              "<IPython.core.display.Javascript object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    }
  ]
}